#ecoding=utf-8

import logging
import random
logger = logging.getLogger("myuseragent_middleware")
logger.setLevel("WARNING")

class myuseragent_middleware(object):
	def __init__(self, settings, user_agent=""):
		self.user_agent = user_agent
		self.logger=logger
		self.uagents=settings['USER_AGENT_LIST']

	@classmethod
	def from_crawler(cls, crawler):
		return cls(crawler.settings)

	def process_request(self, request, spider):
		ua=random.choice(self.uagents)
		logger.info("the used user agent is %s",ua)
		request.headers.setdefault("USER-AGENT", ua)
